const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');

module.exports = {
    mode: 'development',
    entry: "./src/views/app.js",
    target: "electron-renderer",
    resolve: {
        alias: {
            vue: 'vue/dist/vue.esm.js'
        }
    },
    output: {
        filename: "bundle.js",
        path: path.resolve(__dirname, "./dist"),
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.css$/,
                use: ExtractTextPlugin.extract({
                    fallback: "vue-style-loader",
                    use: "css-loader"
                }),
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)$/,
                loader: 'file-loader'
            },
            {
                test: /\.(png|jpg|gif)$/,
                loader: 'file-loader',
                query: {
                    name: '[name].[ext]?[hash]'
                }
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new VueLoaderPlugin(),
        new ExtractTextPlugin('bundle.css'),
        new webpack.HotModuleReplacementPlugin(),
        new HtmlWebpackPlugin({
            title: '爱换壁纸',
            inject: true,
            hash: true,
            template: './src/views/index.html'
        }),
        new CopyWebpackPlugin([
            {
                from: __dirname + '/src/icons/favicon.ico',
                to: __dirname + '/dist',
            }
            ])
    ],
    devServer:{
        contentBase: '/',
        publicPath: '/',
        historyApiFallback: true,
        port: 8086
    }
};
